package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.RemoteWarehouseService;
import com.ruoyi.system.api.domain.BmWarehouse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 仓库服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteWarehouseFallbackFactory implements FallbackFactory<RemoteWarehouseService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteWarehouseFallbackFactory.class);

    @Override
    public RemoteWarehouseService create(Throwable cause) {
        log.error("仓库服务调用失败:{}", cause.getMessage());
        return new RemoteWarehouseService() {
            @Override
            public AjaxResult getInfo(String warehouseCode) {
                return AjaxResult.error("仓库服务调用失败");
            }

            @Override
            public List<BmWarehouse> getWarehouseList() {
                return null;
            }
        };
    }
}
